import 'dart:convert';

import 'package:fluttertz/jsonserialize/jt_list/data.dart';
import 'package:fluttertz/jsonserialize/jtdetailinfo/data.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fluttertz/jsonserialize/tzuser/data.dart';

class User {
  TzUserData _user = null;

  String uname = "";

  TzUserData get data => _user;

  JtListDatum jtinfo = null; //列表选中的機台
  Jtdetailinfo jtdetailinfo = null;  //列表选中的機台详情
  String registration_id = ""; //极光推送id

  String selectWifi = "";//当前连外网的wifi

  SharedPreferences _prefs;
  
  inittz(Map userJson, String username, String fcmtoken) async {
    try {
      _user = TzUserData.fromJson(userJson);
      _user.username = username;
      _user.fcmtoken = fcmtoken;
      uname = username;

    } catch(e) {
      return print('tzuser init error, msg: $e');
    }

    // await setStringTZ(_user.toJson());
    return _user;
  }

  /// 保存到本地缓存
  setStringTZ(Map userJson) async{
    _prefs = await SharedPreferences.getInstance();
    _prefs.setString('tzuser', json.encode(userJson));
  }

}